function centroids = kMeansInitCentroids(X, K)
%KMEANSINITCENTROIDS This function initializes K centroids that are to be 
%used in K-Means on the dataset X
%   centroids = KMEANSINITCENTROIDS(X, K) returns K initial centroids to be
%   used with the K-Means on the dataset X
%

% You should return this values correctly
centroids = zeros(K, size(X, 2));

% ====================== YOUR CODE HERE ======================
% Instructions: You should set centroids to randomly chosen examples from
%               the dataset X
%

m = size(X, 1);
indexes = zeros(m, 1);
for i = 1:m
  indexes(i) = i;
endfor

for j = 1 : K
  i = randi(size(indexes, 1));
  
  % Copy
  for idx = 1 : size(X, 2)
    centroids(j, idx) = X(indexes(i, 1), idx);
  endfor
  
  indexes = [indexes(1 : i - 1);indexes(i + 1 : size(indexes))];
endfor




% =============================================================

end

